package com.ushio.authservice.user.controller;

import com.ushio.authservice.user.entity.qo.UserAddQo;
import com.ushio.authservice.user.service.UserService;
import com.ushio.commonmodule.utils.JwtUtil;
import com.ushio.commonmodule.pojo.result.Result;
import com.ushio.commonmodule.pojo.user.User;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/user")
@Tag(name = "User API", description = "用户管理接口")
public class UserController {

    @Autowired
    UserService userService;

    @GetMapping("/all")
    @Operation(summary = "获取用户", description = "获取所有用户")
    public Result<List<User>> getUserAll(){
        try{

            User loggedInUser = JwtUtil.parseUser();

            System.out.println(loggedInUser.toString());

            List<User> user = userService.getUserAll();
            return Result.success(user);

        }catch (Exception e){

            e.printStackTrace();

            return Result.fail(e.getMessage());
        }
    }
    @PostMapping("/add-user")
    @Operation(summary = "新增用户信息", description = "新增用户信息")
    public Result<User> addUser(@RequestBody UserAddQo userAddQo){
        try{

            User user = userService.addUser(userAddQo);
            return Result.success(user);

        }catch (Exception e){

            e.printStackTrace();

            return Result.fail(e.getMessage());
        }
    }


}
